'use strict';

var util = require('./util.js');
var api = require('./api.js');

var isFunction = util.isFunction;

function _requestPayment(unifiedParams, success, fail, complete) {
  console.log(unifiedParams);
  var mSuccess = isFunction(success) ? success : function () {};
  var mFail = isFunction(fail) ? fail : function () {};
  var mComplete = isFunction(complete) ? complete : function () {};

  unifiedParams.fail = mFail;
  unifiedParams.success = mSuccess;
  unifiedParams.complete = mComplete;
  wx.requestPayment(unifiedParams);
}

function payCallback(orderNo) {
  console.log(orderNo);
  var url = api.payCallBack();
  url += "?orderNo=" + orderNo;
  api.request(url, 'POST', '', function (res, err) {
    console.log(res);
  });
}

module.exports = {
  requestPayment: _requestPayment,
  payCallback: payCallback
};